use std::fs;
use serde_json;
use crate::cli;
use cli::data_type;

pub fn read_json() {
    let path = "/home/xushuai/config.json";
    println!("{:?}", path);
    let json_data = fs::read_to_string(path).expect("读取 JSON 文件失败");
    println!("{:?}", json_data);
    let mut config: data_type::ConfigData = serde_json::from_str(&json_data).expect("JSON 反序列化失败");
    config.ftarce_config.events.push("new_event".to_string());

    println!("{:?}", config);

    let pretty_json = serde_json::to_string_pretty(&config).expect("JSON 序列化失败");

    // ✅ 写入新文件
    let output_path = "/home/xushuai/config_formatted.json";
    fs::write(output_path, pretty_json).expect("写入 JSON 文件失败");
}